package io.renren.modules.substation.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.modules.substation.entity.*;
import io.renren.modules.substation.service.TInfoAreaInfoService;
import io.renren.modules.substation.service.TInfoDevInfoService;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.entity.SysMenuEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.substation.service.TInfoEfenceInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 电子围栏信息表
 *
 * @author yzx
 * @email sunlightcs@gmail.com
 * @date 2020-06-13 15:02:29
 */
@RestController
@RequestMapping("substation/tinfoefenceinfo")
public class TInfoEfenceInfoController extends AbstractController {
    @Autowired
    private TInfoEfenceInfoService tInfoEfenceInfoService;
    @Autowired
    private TInfoDevInfoService tInfoDevInfoService;
    @Autowired
    private TInfoAreaInfoService tInfoAreaInfoService;
//    @Autowired
//    private TInfoAreaInfoController tInfoAreaInfoService;
    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("substation:tinfoefenceinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tInfoEfenceInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{efenceHostId}")
    @RequiresPermissions("substation:tinfoefenceinfo:info")
    public R info(@PathVariable("efenceHostId") Long efenceHostId){
		TInfoEfenceInfoEntity tInfoEfenceInfo = tInfoEfenceInfoService.getById(efenceHostId);

        return R.ok().put("tInfoEfenceInfo", tInfoEfenceInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("substation:tinfoefenceinfo:save")
    public R save(@RequestBody TInfoEfenceInfoEntity tInfoEfenceInfo){


        ValidatorUtils.validateEntity(tInfoEfenceInfo, AddGroup.class);

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String date = df.format(new Date());// new Date()为获取当前系统时间，也可使用当前时间戳

        tInfoEfenceInfo.setCreateOpr(getUserId().toString());
        tInfoEfenceInfo.setLastOpr(getUserId().toString());
        tInfoEfenceInfo.setLastTime(date);
        tInfoEfenceInfo.setIsVaild("1");
        tInfoEfenceInfo.setCreateTime(date);

        tInfoEfenceInfoService.save(tInfoEfenceInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("substation:tinfoefenceinfo:update")
    public R update(@RequestBody TInfoEfenceInfoEntity tInfoEfenceInfo){
		tInfoEfenceInfoService.updateById(tInfoEfenceInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("substation:tinfoefenceinfo:delete")
    public R delete(@RequestBody Long[] efenceHostIds){
		tInfoEfenceInfoService.removeByIds(Arrays.asList(efenceHostIds));

        return R.ok();
    }


    @RequestMapping("/devlist")
//    @RequiresPermissions("substation:tinfoefenceinfo:devlist")
    public R devlist(){
//        List<SelectItemInfo> retList = new ArrayList<SelectItemInfo>();
//        SelectItemInfo temp0=new SelectItemInfo("--请选择--","");
//        retList.add(temp0);
//        TInfoDevInfoEntity tInfoDevInfoEntity = new TInfoDevInfoEntity();
        List<TInfoDevInfoEntity> dev_List= tInfoDevInfoService.list();
//        for(int i=0;i<dev_List.size();i++)
//        {
//            SelectItemInfo temp=new SelectItemInfo(dev_List.get(i).getDevCode(),dev_List.get(i).getDevCode());
//            retList.add(temp);
//        }

        return R.ok().put("list", dev_List);
    }

    @RequestMapping("/areaDevList")
//    @RequiresPermissions("substation:tinfoefenceinfo:areaDevList")
    public R areaDevList(){
        //查询列表数据
        List<TInfoAreaInfoEntity> areaList = tInfoAreaInfoService.list();

        return R.ok().put("list", areaList);
    }

    @RequestMapping("/efencelist")
//    @RequiresPermissions("substation:tinfoefenceinfo:efencelist")
    public R efencelist(){
        List<TInfoEfenceInfoEntity> efencelist = tInfoEfenceInfoService.list();

        return R.ok().put("list", efencelist);
    }



}
